package cn.ztf.zshop.storage.config;

import cn.ztf.zshop.storage.service.MinioBucketStorage;
import io.minio.MinioClient;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class StorageConfig {
    private final MinioConfig minioConfig;

    @Bean
    @ConditionalOnProperty(prefix = "minio", name = "endpoint", havingValue = "true", matchIfMissing = true)// 当这个属性存在的时候才会注入这个bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(minioConfig.getEndpoint())
                .credentials(minioConfig.getAccessKey(), minioConfig.getSecretKey())
                .build();
    }



}
